﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZSPG_YYBCJFHControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Bind();
            if (!base.Page.IsPostBack) { QSDataDLL(); }
        }
        protected void Go_Search(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            Button btnsearch = (Button)FindControl("btnSeach");
            btnsearch.Click += new EventHandler(Go_Search);
            DataTable dt = _EluZSDataProvider.GetProUnList("", GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID" };
            CustomGridList1.DataBind();
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected string GetSqlWhere()
        {
            string sqlWhere = string.Empty;
            TextBox xmmc = (TextBox)FindControl("txtProName");
            TextBox lxh = (TextBox)FindControl("txtProNo");
            TextBox xkzh = (TextBox)FindControl("txtPGJG");
            TextBox jsdw = (TextBox)FindControl("txtComm");
            DropDownList DropDownList1 = (DropDownList)FindControl("DropDownList1");
            if (!string.IsNullOrEmpty(xmmc.Text.Trim()))
            {
                sqlWhere += " and t.项目名称  like '%" + xmmc.Text + "%'";
            }
            if (!string.IsNullOrEmpty(lxh.Text.Trim()))
            {
                sqlWhere += " and t.立项号 like '%" + lxh.Text + "%'";
            }
            if (!string.IsNullOrEmpty(xkzh.Text.Trim()))
            {
                sqlWhere += " and t1.已通过征收评估机构 like '%" + xkzh.Text + "%'";
            }
            if (!string.IsNullOrEmpty(jsdw.Text.Trim()))
            {
                sqlWhere += " and t.建设单位 like '%" + jsdw.Text + "%'";
            }
            if (!string.IsNullOrEmpty(DropDownList1.SelectedValue))
            {
                sqlWhere += " and t.区属 = '" + DropDownList1.SelectedValue + "'";
            }
            if (!string.IsNullOrEmpty(userid))
            {
                string tt = _EluZSDataProvider.CkComType(userid);
                if (tt == "评估机构")
                {
                    sqlWhere += @" and t1.已通过征收评估机构 like '%'|| (select 单位名称 from zs_company where id in (
select cid from zs_user_company where userid='" + userid + "')) ||'%' ";
                }
                else
                {
                    if (_EluZSDataProvider.IsQZSBM(userid) && !_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsSZSB(userid))
                    {
                        sqlWhere += @" and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||t.区属||'%' ";
                    }
                }

            }
            sqlWhere += " order by addtime desc";
            return sqlWhere;
        }
        protected void QSDataDLL()
        {
            DropDownList DropDownList1 = (DropDownList)FindControl("DropDownList1");
            List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("区属");
            EluZSProvider.Params newparam = new EluZSProvider.Params();
            _params.Insert(0, newparam);
            DropDownList1.DataSource = _params;
            DropDownList1.DataValueField = "keyname";
            DropDownList1.DataTextField = "keyname";
            DropDownList1.DataBind();
        }
    }
}


